﻿using InChatter.Client.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace InChatter.Client.WPFDemo
{
    /// <summary>
    /// MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            string loginClient = "";
            LoginWindow win = new LoginWindow();
            win.ShowDialog();
            loginClient = win.LoginClient;
            if (string.IsNullOrEmpty(loginClient))
            {
                Application.Current.Shutdown();
                return;
            }
            List<ClientContext> list = new List<ClientContext>();
            for (int i = 0; i < 10; i++) {
                ClientContext client = new ClientContext();
                client.ClientId = "client" + i;
                client.ClientName = "client"+i;
                client.IsOnline = false;
                list.Add(client);
            }
            mesControl.ClientsSource = list;
            mesControl.LoginId = ClientContext.AllClients.FirstOrDefault(client=>client.ClientName==loginClient).ClientId;
            this.Closing+=MainWindow_Closing;
        }
        private void MainWindow_Closing(object sender, EventArgs e)
        {
            ClientContext.Current = null;
        }
    }
}
